package net.onecloud.onecloud.account.record;

import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import net.onecloud.onecloud.R;
import net.onecloud.onecloud.adapter.RecordAdapter;
import net.onecloud.onecloud.application.App;
import net.onecloud.onecloud.base.BaseAppCompatActivity;
import net.onecloud.onecloud.model.ResultRecord;
import net.onecloud.onecloud.network.NetWork;
import net.onecloud.onecloud.utils.RecycleViewDivider;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class RecordActivity extends BaseAppCompatActivity {


    private RecyclerView mRecyclerView;
    private RecyclerView.LayoutManager mLayoutManager;
    private RecordAdapter mRecordAdapter;

    Observer<ResultRecord> queryRecordObserver = new Observer<ResultRecord>() {
        @Override
        public void onCompleted() {

        }

        @Override
        public void onError(Throwable e) {

        }

        @Override
        public void onNext(ResultRecord resultRecord) {
            if (resultRecord.getSuccess() == 1) {
                mRecordAdapter.setNewData(resultRecord.getData());

            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);
        setToolBarTitle("投递记录");
        HideLeftButton(false);
        initVies();
        initListener();
        initData();
    }

    private void initData() {
        NetWork.getRecordApi()
                .query1(App.getUser().getId())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(queryRecordObserver);

    }

    private void initListener() {
    }

    private void initVies() {
        mRecyclerView = (RecyclerView) findViewById(R.id.m_recyclerview);
        mLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.addItemDecoration(
                new RecycleViewDivider(this, LinearLayoutManager.VERTICAL));
        mRecordAdapter = new RecordAdapter();
        mRecyclerView.setAdapter(mRecordAdapter);
    }
}
